package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.FindCourseDaoljc;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class FindCourseDaoImplljc implements FindCourseDaoljc{

	@Override
	public JSONArray findCourse() {
		JSONArray j = new JSONArray();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT course.cname,course.cid FROM course");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				JSONObject j1 = new JSONObject();
				j1.put("id", rs.getInt("cid"));
				j1.put("text", rs.getString("cname"));
				j.add(j1);	
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return j;
	}

}
